use egui::{Color32, Vec2};
use QcUI::component::{Button, FlexDirection, Panel};

use crate::inspector::{ComponentState, InspectorContext, InspectorTrait};

impl InspectorTrait for Panel {
    fn inspector(&mut self, ctx: &mut InspectorContext, state: &mut ComponentState) {
        egui::CollapsingHeader::new("Label")
            .default_open(true)
            .show(ctx.ui, |ui| {
                ui.group(|ui| {
                    ui.set_min_width(ui.available_width() - 5.);
                    egui::Grid::new("Label")
                        .num_columns(2)
                        .min_col_width(70.)
                        .spacing(Vec2::new(10., 10.))
                        .show(ui, |ui| {
                            ui.label("排列顺序");
                            ui.horizontal(|ui| {
                                let mut text = egui::RichText::new("行模式");

                                let button = if let FlexDirection::Row = self.orientation {
                                    text = text.color(Color32::BLACK);
                                    egui::Button::new(text).fill(Color32::from_rgb(97, 175, 238))
                                } else {
                                    egui::Button::new(text)
                                };

                                if ui.add(button).clicked() {
                                    self.orientation = FlexDirection::Row;
                                }
                                ui.add_space(10.);
                                let mut text = egui::RichText::new("列模式");

                                let button = if let FlexDirection::Column = self.orientation {
                                    text = text.color(Color32::BLACK);
                                    egui::Button::new(text).fill(Color32::from_rgb(97, 175, 238))
                                } else {
                                    egui::Button::new(text)
                                };

                                if ui.add(button).clicked() {
                                    self.orientation = FlexDirection::Column;
                                }
                            });
                            ui.end_row();

                            ui.label("间隔");
                            ui.add(egui::DragValue::new(&mut self.spacing).speed(0.1));
                            ui.end_row();
                        })
                });
            });
    }
}
